{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5c32804c-8dd6-459e-9d12-29e86cc0bd44",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入一行字符串:  123\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "英文字母个数: 0\n",
      "空格个数: 0\n",
      "数字个数: 3\n",
      "其他字符个数: 0\n"
     ]
    }
   ],
   "source": [
    "def count_characters(input_string):\n",
    "    letters = 0\n",
    "    spaces = 0\n",
    "    digits = 0\n",
    "    others = 0\n",
    "\n",
    "    for char in input_string:\n",
    "        if char.isalpha():  # 检查是否是英文字母\n",
    "            letters += 1\n",
    "        elif char.isspace():  # 检查是否是空格\n",
    "            spaces += 1\n",
    "        elif char.isdigit():  # 检查是否是数字\n",
    "            digits += 1\n",
    "        else:  # 其他字符\n",
    "            others += 1\n",
    "\n",
    "    return letters, spaces, digits, others\n",
    "\n",
    "# 主程序\n",
    "input_string = input(\"请输入一行字符串: \")\n",
    "letters, spaces, digits, others = count_characters(input_string)\n",
    "\n",
    "print(f\"英文字母个数: {letters}\")\n",
    "print(f\"空格个数: {spaces}\")\n",
    "print(f\"数字个数: {digits}\")\n",
    "print(f\"其他字符个数: {others}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2ddd4cbc-0904-4b0a-b64e-20fcfdbcff58",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
